package com.itheima.lj.net;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;


import static android.R.string.ok;
import static android.os.Build.HOST;

/**.
 * AsyncHttpClient 的代理类
 */
public class ApiHttpClient {
    private static  AsyncHttpClient client;
    private static String HOST_URL="http://10.0.2.2:8080";
    //传递 单一的AsyncHttpClient对象，并且对AsyncHttpClient对象作初始化操作
    // 比如设置相同的请求头
    public static void setHttpClient(AsyncHttpClient c) {
        client=c;
        //设置请求头，对单例的网络访问对象进行包装
        client.addHeader("Accept-Language", "zh_CN");
        client.addHeader("Connection", "Keep-Alive");
    }
    //代理AsyncHttpClient的get网络请求方法
    public static void getData(String urlPath, AsyncHttpResponseHandler listener) {
        String realUrl=HOST_URL+urlPath;
        // urlPath="oschina/list/news/page0.xml"
        //// realUrl="http://10.0.2.2:8080/oschina/list/news/page0.xml";
        client.get(realUrl,listener);
    }
    //代理了AsyncHttpClient的post网络请求方法
}
